package leecode

import "math"

func maxProduct(nums []int) int {
	result := math.MinInt
	pre, suf := 1, 1
	for i := 0; i < len(nums); i++ {
		var temp int
		//遇到0重置
		if nums[i] == 0 {
			pre = 1
		} else {
			pre = pre * nums[i]
			temp = pre
		}
		//后缀
		if nums[len(nums)-i-1] == 0 {
			suf = 1
		} else {
			suf = suf * nums[len(nums)-i-1]
			temp = max(temp, suf)
		}
		// 只根候选最大值对比
		result = max(result, temp)
	}
	return result
}
